import Vue from 'vue'
import Vuex from 'vuex'
// 安装插件
import createPersisteDstate from 'vuex-persistedstate'
import { getUserINfoAPI } from '@/api'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: '',
    userInfo: {}
  },
  getters: {
    nickname: state => state.userInfo.nickname, // 昵称
    username: state => state.userInfo.username, // 名称
    user_pic: state => state.userInfo.user_pic // 图片路径
  },
  mutations: {
    updataToken(state, val) {
      state.token = val
    },
    updataInfo(state, val) {
      state.userInfo = val
    }
  },
  actions: {
    async getUserINfoActions(store) {
      console.log('调用了用户信息')
      const res = await getUserINfoAPI()
      console.log(res)
      store.commit('updataInfo', res.data.data)
    }
  },
  modules: {
  },

  plugins: [createPersisteDstate()]
})
